package com.bean.newsBang;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class SlideHelp extends Activity implements OnGestureListener,OnTouchListener{
	
    private GestureDetector detector;  
    private ViewFlipper flipper;
    private int cp = 1;
    private int totalPage = 5;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.slidehelp);
        
        flipper = (ViewFlipper) this.findViewById(R.id.viewFlipper);
        detector = new GestureDetector(this);
        flipper.setOnTouchListener(this);
        flipper.setLongClickable(true);
    }

	public boolean onDown(MotionEvent arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		float x0 = arg0.getX();
		float x1 = arg1.getX();

		if(x0-x1>100){
			if(cp<this.totalPage){
				cp++;
		        flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in));  
		        flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_out));
		        flipper.showNext();
			}
			else{
				this.finish();
			}
		}
		else if(x0-x1<-100){
			if(cp>1){
				cp--;
	            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_in));  
	            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_out));  
	            this.flipper.showPrevious();  
			}
		}
		else{
			Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
		}
		
		return false;
	}

	public void onLongPress(MotionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		return false;
	}

	public void onShowPress(MotionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public boolean onSingleTapUp(MotionEvent arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		return detector.onTouchEvent(arg1);
	}
}